package com.itic.system.collage.collage.service;

import com.itic.appbase.applications.redis.IRedisDao;
import com.itic.appbase.framework.Base.BaseCode;
import com.itic.appbase.framework.common.constants.DBConst;
import com.itic.appbase.framework.type.*;
import com.itic.appbase.framework.utils.DateHelper;
import com.itic.appbase.framework.utils.HttpRequestUtils;
import com.itic.system.carrage.template.service.CarrageTemplateService;
import com.itic.system.collage.category.persistence.model.CollageCategory;
import com.itic.system.collage.category.service.CollageCategoryService;
import com.itic.system.collage.condition.persistence.model.CollageCondition;
import com.itic.system.collage.condition.service.CollageConditionService;
import com.itic.system.collage.imageVideo.persistence.model.CollageImageVideo;
import com.itic.system.collage.imageVideo.service.CollageImageVideoService;
import com.itic.system.collage.sku.persistence.model.CollageSku;
import com.itic.system.collage.sku.service.CollageSkuService;
import com.itic.system.collage.skuProperty.persistence.model.CollageSkuProperty;
import com.itic.system.collage.skuProperty.service.CollageSkuPropertyService;
import com.itic.system.order.order.persistence.model.Order;
import com.itic.system.order.order.service.OrderService;
import com.itic.system.spu.category.persistence.model.SpuCategory;
import com.itic.system.spu.category.service.SpuCategoryService;
import com.itic.system.user.address.persistence.model.UserAddress;
import com.itic.system.user.address.persistence.model.UserAddressExample;
import com.itic.system.user.address.service.UserAddressService;
import com.itic.system.user.attention.persistence.model.UserAttention;
import com.itic.system.user.attention.service.UserAttentionService;
import com.itic.system.user.user.persistence.model.HppUser;
import com.itic.system.user.user.service.HppUserService;
import com.itic.system.vo.*;
import net.sf.json.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.formula.functions.Odd;
import org.apache.xmlbeans.impl.xb.xsdschema.LocalSimpleType;
import org.aspectj.weaver.ast.Or;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.itic.appbase.framework.common.service.CrudService;
import com.itic.system.collage.collage.persistence.dao.CollageDao;
import com.itic.system.collage.collage.persistence.model.Collage;
import com.itic.system.collage.collage.persistence.model.CollageExample;
import com.itic.system.collage.collage.persistence.model.CollageExample.Criteria;
import sun.font.LayoutPathImpl;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;


@Service
@Transactional
public class CollageService
     extends CrudService<CollageDao,Collage,CollageExample> {
    @Autowired
    private CollageDao collageDao;
    @Autowired
    private HppUserService hppUserService;
    @Autowired
    private CollageImageVideoService collageImageVideoService;
    @Autowired
    private SpuCategoryService spuCategoryService;
    @Autowired
    private CollageCategoryService collageCategoryService;
    @Autowired
    private CollageSkuService collageSkuService;
    @Autowired
    private CollageConditionService collageConditionService;
    @Autowired
    private UserAttentionService userAttentionService;
    @Autowired
    private CarrageTemplateService carrageTemplateService;
    @Autowired
    private UserAddressService userAddressService;
    @Autowired
    private OrderService orderService;
    @Autowired
    private CollageSkuPropertyService collageSkuPropertyService;
    @Autowired
    private IRedisDao<String,Object> redisDao;

    /**
     * 下一步保存用户基本信息
     * @param userId  发布人
     * @param collageId 拼团Id
     * @param title 标题
     * @param descript 描叙
     * @param imageVieos 图片和视频集合 ImageVideoVo
     * @param localAddress  定位地址
     * @return
     */
    public Map<String,Object> nextStep(String userId, String collageId, String title, String descript, List<ImageVieoVo> imageVieos, String localAddress){
        Map<String,Object> resultMap = new HashMap<>();
        //根据用户Id获取用户
        HppUser hppUser = this.hppUserService.get(userId);
        if(hppUser!=null){
            //处理下一步保存 判断collageId是否存在 存在就进行修改
            if(StringUtils.isEmpty(collageId)){
                //添加下一步保存基本信息
                Collage collage = this.addCollage(title, descript, localAddress, hppUser.getId());
                collageId = collage.getId();
            }else{
                //修改拼团的下一步的基本消息
                Collage collage = this.get(collageId);
                if(collage!=null)
                    this.editCollage(collage,title,descript,localAddress);
            }
            //删除所有的视频和图片重新添加
            this.collageImageVideoService.addOrEditCollageImageVideo(collageId,imageVieos);
            resultMap.put(BaseCode.DATA,collageId);
            resultMap.put(BaseCode.CODE,BaseCode.SUCCESS_ERROR_CODE);
            resultMap.put(BaseCode.MSG,BaseCode.SUCCESS_ERROR_MSG);
        }else{
            resultMap.put(BaseCode.CODE,BaseCode.HPP_USER_NOT_EXSIT_CODE);
            resultMap.put(BaseCode.MSG,BaseCode.HPP_USER_NOT_EXSIT_MSG);
        }
        return resultMap;
    }

    /**
     * 添加拼团下一步基本信息
     * @param title 标题
     * @param descript 描叙
     * @param localAddress 定位地址
     * @param userId 发布人Id
     * @return
     */
    public Collage addCollage( String title, String descript, String localAddress,String userId){
        Collage collage = new Collage();
        collage.setTitle(title);
        collage.setLocaltionAddress(localAddress);
        collage.setDescription(descript);
        collage.setUserId(userId);
        String result = this.add(collage);
        if(SUCCESS.equals(result))
            return collage;
        else
            return null;
    }

    /**
     * 编辑hpp的基本信息
     * @param collage
     * @param title
     * @param descript
     * @param localAddress
     * @return
     */
    public String editCollage( Collage collage,String title, String descript, String localAddress){
        collage.setTitle(title);
        collage.setLocaltionAddress(localAddress);
        collage.setDescription(descript);
        String result = this.edit(collage);
        return result;
    }

    /**
     * 添加或者编辑商品属性类型  属性值
     * @param userId
     * @param spuCategoryId
     * @param skuNameStrs
     * @param collageId
     * @param collageCategoryId
     * @return
     */
    public Map<String,Object> addOrEditSku(String userId, String spuCategoryId, String skuNameStrs, String collageId, String collageCategoryId){
        Map<String,Object> resultMap = new HashMap<>();
        Collage collage = this.get(collageId);
        String categoryId = collageCategoryId;
        //判断用户是否和发布拼团的人一致
        if(collage!=null && userId.equals(collage.getUserId())){
            //查询系统商品属性类型
            SpuCategory spuCategory = this.spuCategoryService.get(spuCategoryId);
            //判断是修改是添加
            if(StringUtils.isEmpty(collageCategoryId)){
                //添加拼团属性 以及属性类型
                CollageCategory category = this.collageCategoryService.addCollageCategory(collageId,spuCategory.getId(),spuCategory.getName());
                categoryId = category.getId();
            }else{
                //根据collageCategoryId查询拼团属性类型
                CollageCategory category = this.collageCategoryService.get(collageCategoryId);
                if(category!=null){
                    this.collageCategoryService.editCollageCategory(category,spuCategory.getId(),spuCategory.getName());
                    //删除collageCategoryId下所有的属性值名称
                    this.collageSkuService.delBatchCollageSkuByCategoryId(collageCategoryId);
                }
            }
            //添加属性类型下的属性值名称
            String skuNames[] = skuNameStrs.split(",");
            for(String skuName : skuNames){
                this.collageSkuService.addCollageSku(categoryId,skuName,collageId);
            }
            //添加或者修改类型匹配  (采用全删除，后添加策略)
            resultMap.put(BaseCode.CODE,BaseCode.SUCCESS_ERROR_CODE);
            resultMap.put(BaseCode.MSG,BaseCode.SUCCESS_ERROR_MSG);
        }else{
            resultMap.put(BaseCode.CODE,BaseCode.HPP_SELF_USER_NOT_ACCORDANCE_CODE);
            resultMap.put(BaseCode.MSG,BaseCode.HPP_SELF_USER_NOT_ACCORDANCE_MSG);
        }
        return resultMap;
    }

    /**
     * 拼团提交信息
     * @param collageVo
     * @return
     */
    public Map<String,Object> submit(CollageVo collageVo){
        Map<String, Object> resultMap = new HashMap<String,Object>();
        //总库存数
        int totalInventorys = collageVo.getTotalInventorys() ==null?1:collageVo.getTotalInventorys().intValue();
        //一人最多购买几次
        int maxBuyCount = collageVo.getMaxBugCount() ==null?1:collageVo.getMaxBugCount().intValue();
        List<CollagePriceVo> collagePriceVos = collageVo.getCollagePriceVo();
        //最大成团人数
        int maxPeopleCount = this.findMaxCollagePriceVo(collagePriceVos);
        //判断总库存是否大于成团人数 * 一人最多购买数量
        if(totalInventorys >=(maxBuyCount * maxPeopleCount)){
            //根据拼团Id查询拼团
            Collage collage = this.get(collageVo.getCollageId());
            if(collageVo.getUserId().equals(collage.getUserId())){
                //判断拼团类型
                CollageType collageType  = CollageType.getCollageType(collageVo.getCollageType());
                //添加拼团基本信息
                //支付方式
                PayMethod payMethod = PayMethod.getPayMethod(collageVo.getPayMethod());
                //发货方式
                DeliveryMethod deliveryMethod = DeliveryMethod.getDeliveryMethod(collageVo.getDeliveryMethod());
                switch (collageType){
                    case Common:
                        //添加普通拼团
                        this.addCommonCollage(collage,collage.getUserId(),collageVo.getOriginalPrice(),collageVo.getCollageTime(),deliveryMethod,payMethod,collageVo.getMaxBugCount(),collageVo.getTotalInventorys(),collageType,collageVo.getCarrageId());
                        break;
                    case  Ladder:
                        //添加阶梯拼团 (定金 补款时间)
                        this.addLadderCollage(collage,collage.getUserId(),collageVo.getOriginalPrice(),collageVo.getCollageTime(),deliveryMethod,payMethod,collageVo.getMaxBugCount(),collageVo.getTotalInventorys(),collageType,collageVo.getCarrageId(),collageVo.getDepositMoney(),collageVo.getSupplementValidity());
                        break;
                }
                //添加拼团成团人数 与价格
                //拼团最大人数
                int collageMaxPeopleCount = 1;
                for(CollagePriceVo collagePriceVo:collagePriceVos ){
                    this.collageConditionService.addCollageCondition(collageVo.getCollageId(),collagePriceVo.getPeopleCount(),collagePriceVo.getCollagePrice());
                    if(collageMaxPeopleCount < collagePriceVo.getPeopleCount())
                        collageMaxPeopleCount = collagePriceVo.getPeopleCount();
                }
                //限制成团时间
                int minut = collageVo.getCollageTime()==null?1:collageVo.getCollageTime();
                //添加拼团最大人数到redis,方便加锁 (失效时间为拼团结束时间)
                this.redisDao.set(RedisKey.CollageMaxPeopleCount+collage.getId(),collageMaxPeopleCount,minut*60);
                resultMap.put(BaseCode.CODE,BaseCode.SUCCESS_ERROR_CODE);
                resultMap.put(BaseCode.MSG,BaseCode.SUCCESS_ERROR_MSG);
            }else{
                // 操作用户和发布人不一致
                resultMap.put(BaseCode.CODE,BaseCode.HPP_SELF_USER_NOT_ACCORDANCE_CODE);
                resultMap.put(BaseCode.MSG,BaseCode.HPP_SELF_USER_NOT_ACCORDANCE_MSG);
            }
        }else{
            //提示总库存大于成团人数乘以购买次数
            resultMap.put(BaseCode.CODE,BaseCode.HPP_INVENTORYS_GREAT_THAN_BUY_AND_PEOPLE_CODE);
            resultMap.put(BaseCode.MSG,BaseCode.HPP_INVENTORYS_GREAT_THAN_BUY_AND_PEOPLE_MSG);
        }
        return resultMap;
    }

    /**
     *  获取拼团中最大的成团人数
     * @param collagePriceVos
     * @return
     */
    public   int findMaxCollagePriceVo( List<CollagePriceVo> collagePriceVos) {
        int max = collagePriceVos.get(0).getPeopleCount();
        for(int i=0;i<collagePriceVos.size();i++){
            if(collagePriceVos.get(i).getPeopleCount()>max)   // 判断最大值
                max=collagePriceVos.get(i).getPeopleCount();
        }
        return max;
    }

    /**
     * 添加普通拼团的数据
     * @param userId
     * @param originalPrice
     * @param collageTime
     * @param deliveryMethod
     * @param payMethod
     * @param maxBugCount
     * @param totalInventorys
     * @param collageType
     * @return
     */
    public String  addCommonCollage(Collage collage,String  userId, double originalPrice, int collageTime, DeliveryMethod deliveryMethod, PayMethod payMethod,int maxBugCount,int totalInventorys,CollageType collageType,String carrageId){
        //计算限制结束时间
        this.generalCollage(collage,userId, originalPrice, collageTime, deliveryMethod, payMethod, maxBugCount, totalInventorys, collageType,carrageId);
        String result = this.edit(collage);
        return result;
    }

    /**
     * 添加阶梯拼团信息
     * @param userId
     * @param originalPrice
     * @param collageTime
     * @param deliveryMethod
     * @param payMethod
     * @param maxBugCount
     * @param totalInventorys
     * @param collageType
     * @param depositMoney
     * @param supplementValidity
     * @return
     */
    public String  addLadderCollage(Collage collage,String  userId, double originalPrice, int collageTime, DeliveryMethod deliveryMethod, PayMethod payMethod,int maxBugCount,int totalInventorys,CollageType collageType,String carrageId,double depositMoney,Date supplementValidity){
        this.generalCollage(collage,userId, originalPrice, collageTime, deliveryMethod, payMethod, maxBugCount, totalInventorys, collageType,carrageId);
        collage.setDepositMoney(depositMoney);
        collage.setSupplementValidity(supplementValidity);
        String result = this.edit(collage);
        return result;
    }

    /**
     * 初始化拼团基本信息
     * @param userId
     * @param originalPrice
     * @param collageTime
     * @param deliveryMethod
     * @param payMethod
     * @param maxBugCount
     * @param totalInventorys
     * @param collageType
     * @return
     */
    public Collage generalCollage(Collage collage,String  userId, double originalPrice, int collageTime, DeliveryMethod deliveryMethod, PayMethod payMethod,int maxBugCount,int totalInventorys,CollageType collageType,String carrageId){
        collage.setUserId(userId);
        collage.setOriginalPrice(originalPrice);
        //计算限制结束时间
        Date collageEedTime =  DateHelper.addTime(new Date(),collageTime, Calendar.MINUTE);
        //拼团结束时间
        collage.setCollageFinishTime(collageEedTime);
        //拼团限制时间
        collage.setCollageLimitTime(collageTime);
        //拼团限制时间单位
        collage.setCollageLimitTimeUnit(CollageUnitType.Minute.getUnit());
        collage.setPayMethod(payMethod.getMethod());
        collage.setDeliverMethod(deliveryMethod.getMethod());
        //完成发布
        collage.setIsFinishSend("1");
        switch (deliveryMethod){
            case Self:
                break;
            case Delivery:
                //运费模板
                collage.setCarrageTemplateId(carrageId);
                break;
            case QCode:
                break;
            case VirtualCode:
                break;
        }
        collage.setPayMethod(payMethod.getMethod());
        collage.setMaxCount(maxBugCount);
        collage.setTotalInventorys(totalInventorys);
        collage.setCollageType(collageType.getType());
        return collage;
    }

    /**
     * 拼团列表页
     * 分页查询
     * @param example
     * @param userId
     * @return
     */
    public Map<String,Object> collageList(CollageExample example,String userId){
        //查询我所关注的人
        Map<String,Object> resultMap = new HashMap<>();
      /*  List<UserAttention> userAttentions = this.userAttentionService.findMyAllAttention(userId);
        List<String> userIds = new ArrayList<>();
        for(UserAttention userAttention : userAttentions)
            userIds.add(userAttention.getAttentionUserId());
        userIds.add(userId);*/
        Criteria criteria = example.createCriteria();
        criteria.andIsEffectiveEqualTo(DBConst.TRUE);
        //criteria.andUserIdIn(userIds);
        criteria.andIsFinishSendEqualTo("1");
        List<Collage> collages = this.list(example);
        List<CollageListVo> collageListVos = new ArrayList<>();
        for(Collage collage : collages){
            CollageListVo collageListVo = new CollageListVo();
            //查看发布人
            HppUser hppUser = this.hppUserService.get(collage.getUserId());
            if(hppUser!=null){
                collageListVo.setHeadImage(hppUser.getHeadImg());
                collageListVo.setNickName(hppUser.getNickName());
            }
            collageListVo.setCollageId(collage.getId());
            collageListVo.setTitle(collage.getTitle());
            //拼团类型
            //CollageType collageType = CollageType.getCollageType(collage.getCollageType());
            collageListVo.setCollageType(collage.getCollageType());
            List<CollageImageVideo> collageImageVideos = this.collageImageVideoService.findCollageImageVideoByCollageIdAndType(collage.getId(),ImageVideoType.Image);
            if(!collageImageVideos.isEmpty())
                collageListVo.setMainImage(collageImageVideos.get(0).getUrl());
            collageListVo.setOriginPrice(collage.getOriginalPrice());
            List<CollageCondition> collageConditions = this.collageConditionService.findCollageConditionByCollageId(collage.getId());
            if(!collageConditions.isEmpty()){
                //几人成团
                collageListVo.setRequireCount(collageConditions.get(0).getCollagePeopleNumber());
                //拼团价
                collageListVo.setCollagePrice(collageConditions.get(0).getCollagePrice());
            }
            //几人参团
            int joinCount = this.orderService.findOrderCountByCollageId(collage.getId());
            collageListVo.setJoinCount(joinCount);
            //结束时间描叙
            String endTimeContent = this.getDifferDate(collage.getCollageFinishTime(),new Date());
            collageListVo.setEndTimeContent(endTimeContent);
            //拼团结束状态
            CollageEndState collageEndState = this.IsCollageEnd(collage);
            //拼团状态   拼团人数够了,拼团
            collageListVo.setState(collageEndState.getState());
            collageListVos.add(collageListVo);
        }
        resultMap.put(BaseCode.DATA,collageListVos);
        resultMap.put(BaseCode.CODE,BaseCode.SUCCESS_ERROR_CODE);
        resultMap.put(BaseCode.MSG,BaseCode.SUCCESS_ERROR_MSG);
        return resultMap;
    }

    /**
     * 拼团详情
     * @param collageId
     * @return
     */
    public Map<String,Object> collageDetail(String collageId){
        Map<String,Object> resultMap = new HashMap<>();
        Collage collage = this.get(collageId);
        if(collage!=null){
            //轮播图 或者是视频
            CollageDetailVo collageDetailVo = new CollageDetailVo();
            List<CollageImageVideo> collageImageVideos = this.collageImageVideoService.findCollageImageVideoByCollageId(collage.getId());
            List<ImageVieoVo> imageVieoVos = new ArrayList<>();
            for(CollageImageVideo collageImageVideo : collageImageVideos){
                ImageVieoVo imageVieoVo = this.collageImageVideoWrapToImageVieoVo(collageImageVideo);
                imageVieoVos.add(imageVieoVo);
            }
            //图片
            collageDetailVo.setImageVieoVos(imageVieoVos);
            //标题
            collageDetailVo.setTitle(collage.getTitle());
            collageDetailVo.setOriginalPrice(collage.getOriginalPrice());
            //拼团价
            List<CollageCondition> collageConditions = this.collageConditionService.findCollageConditionByCollageId(collage.getId());
            List<CollagePriceVo> collagePriceVos = new ArrayList<>();
            for(CollageCondition collageCondition :collageConditions ){
                CollagePriceVo collagePriceVo = this.collageConditionWrapCollagePriceVo(collageCondition);
                collagePriceVos.add(collagePriceVo);
            }
            collageDetailVo.setCollagePriceVos(collagePriceVos);
            if(!collagePriceVos.isEmpty())
            //几人成团
            collageDetailVo.setRequireCount(collagePriceVos.get(0).getPeopleCount());
            //几人参团
            int joinCount = this.orderService.findOrderCountByCollageId(collage.getId());
            collageDetailVo.setJoinColage(joinCount);
            //发货方式
            DeliveryMethod deliveryMethod = DeliveryMethod.getDeliveryMethod(collage.getDeliverMethod());
            collageDetailVo.setSendType(deliveryMethod.getMethod());
            collageDetailVo.setSendName(deliveryMethod.getName());
            //定位
            collageDetailVo.setLocalAddress(collage.getLocaltionAddress());
            //详情描叙
            collageDetailVo.setDescript(collage.getDescription());
            HppUser user = this.hppUserService.get(collage.getUserId());
            //关于团长
            collageDetailVo.setAboutCollage(user.getAboutMe());
            //团长
            collageDetailVo.setNickName(user.getNickName());
            //团长头像
            collageDetailVo.setHeadImage(user.getHeadImg());
            //发布人
            collageDetailVo.setUserId(user.getId());
            //团长手机号
            collageDetailVo.setPhone(user.getPhone());
            //拼团Id
            collageDetailVo.setCollageId(collage.getId());
            //拼团类型
            CollageType collageType = CollageType.getCollageType(collage.getCollageType());
            collageDetailVo.setCollageType(collageType.getType());
            //结束时间描叙
            String endTimeContent = this.getDifferDate(collage.getCollageFinishTime(),new Date());
            collageDetailVo.setEndTimeContent(endTimeContent);
            //拼团结束状态
            CollageEndState collageEndState = this.IsCollageEnd(collage);
            collageDetailVo.setCollageState(collageEndState.getState());
            //规格
            List<CollageCategorySkuVo> collageCategorySkuVos = new ArrayList<>();
            //拼团类型
            List<CollageCategory> collageCategories = this.collageCategoryService.findCollageCategoryByCollageId(collage.getId());
            for(CollageCategory category : collageCategories){
                CollageCategorySkuVo collageCategorySkuVo = collageCategoryWrapCollageCategorySkuVo(category);
                collageCategorySkuVos.add(collageCategorySkuVo);
            }
            collageDetailVo.setCollageCategorySkuVos(collageCategorySkuVos);
            //最大购买数量
            collageDetailVo.setMaxBugCount(collage.getMaxCount());
            List<CollageUserVo> collageUserVos = this.findCollageUserByCollageId(collageId);
            collageDetailVo.setCollageUserVos(collageUserVos);
            resultMap.put(BaseCode.DATA,collageDetailVo);
            resultMap.put(BaseCode.CODE,BaseCode.SUCCESS_ERROR_CODE);
            resultMap.put(BaseCode.MSG,BaseCode.SUCCESS_ERROR_MSG);
        }else{
            resultMap.put(BaseCode.CODE,BaseCode.HPP_COLLAGE_NOT_EXIST_CODE);
            resultMap.put(BaseCode.MSG,BaseCode.HPP_COLLAGE_NOT_EXIST_MSG);
        }
        return resultMap;
    }

    /**
     * 效验拼团是否结束
     * @param collage
     * @return
     */
    public CollageEndState IsCollageEnd(Collage collage){
        //效验成团人数是否够了(考虑一下阶梯拼团 阶梯拼团按最小成团人数)
        //参见拼团人数
        CollageSuccess collageSuccess = isSuccessCollage(collage);
        //效验成团时间是否超过现在的时间
        Date endDate = collage.getCollageFinishTime();
        Date nowDate = new Date();
        if(endDate.getTime()<= nowDate.getTime() || CollageSuccess.Success.getState().equals(collageSuccess.getState()) )
            return CollageEndState.End;
        return CollageEndState.NotEnd;
    }

    /**
     * 效验拼团是否成团
     * @param collage
     * @return
     */
    public CollageSuccess isSuccessCollage(Collage collage){
        //效验成团人数是否够了(考虑一下阶梯拼团 阶梯拼团按最小成团人数)
        //参见拼团人数
        int requireCount = 0;
        List<CollageCondition> collageConditions = this.collageConditionService.findCollageConditionByCollageId(collage.getId());
        if(!collageConditions.isEmpty())
            requireCount = collageConditions.get(0).getCollagePeopleNumber();
        int joinCount = this.orderService.findOrderCountByCollageId(collage.getId());
        if(joinCount >= requireCount)
            return CollageSuccess.Success;
        else
            return CollageSuccess.Fail;
    }

    /**
     * 获取拼团距离结束时间相差几天几小时 几分钟
     * @param endDate
     * @param compareDate
     * @return
     */
    private String  getDifferDate(Date endDate,Date compareDate){
        if(endDate.getTime()<=compareDate.getTime()){
            return "已结束";
        }else{
            long day = DateHelper.getDifferDay(endDate,compareDate);
            long hour = DateHelper.getDifferHour(endDate,compareDate);
            long min = DateHelper.getDifferMinute(endDate,compareDate);
            StringBuffer content = new StringBuffer();
            if(day>0)
                content.append(day).append("天");
            if(hour>0)
                content.append(hour).append("小时");
            if(min>0)
                content.append(min).append("分钟");
            return content.toString();
        }
    }

    /**
     * 将图片视频转变成ImageVideoVo
     * @param collageImageVideo
     * @return
     */
    public ImageVieoVo collageImageVideoWrapToImageVieoVo(CollageImageVideo collageImageVideo){
        ImageVieoVo imageVieoVo = new ImageVieoVo();
        imageVieoVo.setType(collageImageVideo.getType());
        imageVieoVo.setUrl(collageImageVideo.getUrl());
        return imageVieoVo;
    }

    /**
     * 将拼团价格人数转换成collagePriceVo
     * @param collageCondition
     * @return
     */
    public CollagePriceVo collageConditionWrapCollagePriceVo(CollageCondition collageCondition){
        CollagePriceVo collagePriceVo = new CollagePriceVo();
        collagePriceVo.setCollagePrice(collageCondition.getCollagePrice());
        collagePriceVo.setPeopleCount(collageCondition.getCollagePeopleNumber());
        return collagePriceVo;
    }

    /**
     * 拼团类型转换成CollageCategorySkuVo
     * @param collageCategory
     * @return
     */
    public CollageCategorySkuVo  collageCategoryWrapCollageCategorySkuVo(CollageCategory collageCategory){
        CollageCategorySkuVo collageCategorySkuVo = new CollageCategorySkuVo();
        collageCategorySkuVo.setCategoryId(collageCategory.getId());
        collageCategorySkuVo.setName(collageCategory.getCategoryName());
        //拼团sku规格
        List<CollageSku> collageSkus =  this.collageSkuService.findCollageSkuByCategoryId(collageCategory.getId());
        List<CollageSkuVo> collageSkuVos = new ArrayList<>();
        for(CollageSku collageSku : collageSkus){
            CollageSkuVo collageSkuVo = collageSkuWrapToCollageSkuVo(collageSku);
            collageSkuVos.add(collageSkuVo);
        }
        collageCategorySkuVo.setCollageSkuVos(collageSkuVos);
        return collageCategorySkuVo;
    }

    /**
     * 拼团规格转换成CollageSkuVo
     * @param collageSku
     * @return
     */
    public CollageSkuVo collageSkuWrapToCollageSkuVo(CollageSku collageSku){
        CollageSkuVo collageSkuVo = new CollageSkuVo();
        collageSkuVo.setSkuName(collageSku.getSkuName());
        collageSkuVo.setPropertyId(collageSku.getId());
        return collageSkuVo;
    }

    public Map<String,Object> calActualPay(String collageId,String addressId,int count){
        Map<String,Object> resultMap = new HashMap<>();
        Collage collage = this.get(collageId);
        if(collage!=null){
            //查看拼团类型
            CollageType collageType = CollageType.getCollageType(collage.getCollageType());
            if(collageType!=null){
                DeliveryMethod deliveryMethod = DeliveryMethod.getDeliveryMethod(collage.getDeliverMethod());
                if(deliveryMethod!=null){
                        //计算实际付款
                        PayActualVo payActualVo = this.calActualPay(collage,addressId,count);
                        //提示成功 返回数据
                        resultMap.put(BaseCode.DATA,payActualVo);
                        resultMap.put(BaseCode.CODE,BaseCode.SUCCESS_ERROR_CODE);
                        resultMap.put(BaseCode.MSG,BaseCode.SUCCESS_ERROR_MSG);
                }else{
                    //提示发货方式不存在
                    resultMap.put(BaseCode.CODE,BaseCode.HPP_DELIVERY_METHOD_NOT_EXIST_CODE);
                    resultMap.put(BaseCode.MSG,BaseCode.HPP_DELIVERY_METHOD_NOT_EXIST_MSG);
                }
            }else{
                //提示拼团类型不存在
                resultMap.put(BaseCode.CODE,BaseCode.HPP_COLLAGE_TYPE_NOT_EXIST_CODE);
                resultMap.put(BaseCode.MSG,BaseCode.HPP_COLLAGE_TYPE_NOT_EXIST_MSG);
            }
        }else{
            //提示订单不存在
            resultMap.put(BaseCode.CODE,BaseCode.HPP_ORDER_NOT_EXIST_CODE);
            resultMap.put(BaseCode.MSG,BaseCode.HPP_ORDER_NOT_EXIST_MSG);
        }
        return resultMap;
    }

    /**
     *  //计算不同拼团类型返回不同的实付款
     * @param collage
     * @return
     */
    public double calActualPayByCollageType(Collage collage,int count) {
        double actualPay = 0;
        CollageType collageType = CollageType.getCollageType(collage.getCollageType());
        List<CollageCondition> collageConditions = this.collageConditionService.findCollageConditionByCollageId(collage.getId());
        if (collageType != null && !collageConditions.isEmpty()) {
            switch (collageType) {
                case Common:
                    actualPay = collageConditions.get(0).getCollagePrice();
                    actualPay = actualPay * count;
                    break;
                case Ladder:
                    //TODO 后期开发 未完待续....
                    break;
            }
        }
        return actualPay;

    }

    /**
     * 计算实付款 以及运费
     * @param collage
     * @param addressId 收货地址Id
     * @param count
     * @return
     */
    public PayActualVo calActualPay(Collage collage,String addressId,int count){

        //根据类型计算实付款
        double actualPay = this.calActualPayByCollageType(collage,count);
        //发货类型 收货地址
        DeliveryMethod deliveryMethod = DeliveryMethod.getDeliveryMethod(collage.getDeliverMethod());
        //计算运费
        String regionId = null;
        if(StringUtils.isNotEmpty(addressId)){
            UserAddress userAddress = this.userAddressService.get(addressId);
            if(userAddress!=null)
                regionId = userAddress.getRegionId();
        }
        double fee = this.carrageTemplateService.calFeeByDeliveryMethod(deliveryMethod,collage.getCarrageTemplateId(),regionId,count);
        PayActualVo payActualVo = new PayActualVo(actualPay,fee);
        return payActualVo;
    }

    /**
     * 支付详情信息
     * @param userId
     * @param collageId
     * @param count
     * @return
     */
    public Map<String ,Object> getPayDetailVo(String userId,String collageId,int count){
        Map<String,Object> resultMap = new HashMap<>();
        Collage collage = this.get(collageId);
        if(collage!=null){
            //效验拼团是否结束
            CollageEndState collageEndState =  this.IsCollageEnd(collage);
            PayDetailVo payDetailVo = new PayDetailVo();
            //拼团Id
            payDetailVo.setCollageId(collage.getId());
            //支付方式
            payDetailVo.setPayType(collage.getPayMethod());
            //发货类型
            payDetailVo.setSendType(collage.getDeliverMethod());
            //拼团状态
            payDetailVo.setState(collageEndState.getState());
            //获取用户收货地址
            List<UserAddress> userAddresses = this.userAddressService.findUserAddressByUserIdAndPage(new UserAddressExample(),userId);
            String addressId = null;
            //收货地址
            if(!userAddresses.isEmpty()){
                UserAddress userAddress = userAddresses.get(0);
                addressId = userAddress.getId();
                payDetailVo.setAddressId(addressId);
                payDetailVo.setAddress(userAddress.getAddress());
                payDetailVo.setReciveName(userAddress.getReceiverName());
                payDetailVo.setRecivePhone(userAddress.getReceiverPhone());
            }
            //实际付款
            //运费
            PayActualVo payActualVo =  calActualPay(collage,addressId,count);
            payDetailVo.setActualPay(payActualVo.getActualPay());
            payDetailVo.setFee(payActualVo.getFee());
            payDetailVo.setCollageUserId(collage.getUserId());
            resultMap.put(BaseCode.DATA,payDetailVo);
            resultMap.put(BaseCode.CODE,BaseCode.SUCCESS_ERROR_CODE);
            resultMap.put(BaseCode.MSG,BaseCode.SUCCESS_ERROR_MSG);
        }else{
            //提示拼团不存在
            resultMap.put(BaseCode.CODE,BaseCode.HPP_COLLAGE_NOT_EXIST_CODE);
            resultMap.put(BaseCode.MSG,BaseCode.HPP_COLLAGE_NOT_EXIST_MSG);
        }
        return resultMap;
    }

    /**
     *  我发布的团
     * @param example
     * @param userId
     * @return
     */
    public  Map<String ,Object> myPublishCollage(CollageExample example ,String userId){
        Map<String ,Object> resultMap = new HashMap<>();
        HppUser hppUser = this.hppUserService.get(userId);
        if(hppUser!=null){
            List<Collage> collages = this.findMyPublishCollageListByUserIdAndPage(example,userId);
            List<MyPublishCollageVo> myPublishCollageVos = new ArrayList<>();
            for(Collage collage : collages){
                MyPublishCollageVo myPublishCollageVo = new MyPublishCollageVo();
                myPublishCollageVo.setNickName(hppUser.getNickName());
                int joinCount = this.orderService.findOrderCountByCollageId(collage.getId());
                myPublishCollageVo.setJoinCount(joinCount);
                myPublishCollageVo.setEffectDate(DateHelper.formatDate(collage.getCollageFinishTime()));
                List<CollageImageVideo> imageVideos = this.collageImageVideoService.findCollageImageVideoByCollageIdAndType(collage.getId(),ImageVideoType.Image);
                if(!imageVideos.isEmpty())
                    myPublishCollageVo.setImage(imageVideos.get(0).getUrl());
                myPublishCollageVos.add(myPublishCollageVo);
            }
            resultMap.put(BaseCode.DATA,myPublishCollageVos);
            resultMap.put(BaseCode.CODE,BaseCode.SUCCESS_ERROR_CODE);
            resultMap.put(BaseCode.MSG,BaseCode.SUCCESS_ERROR_MSG);
        }else{
            //提示用户不存在
            resultMap.put(BaseCode.CODE,BaseCode.HPP_USER_NOT_EXSIT_CODE);
            resultMap.put(BaseCode.MSG,BaseCode.HPP_USER_NOT_EXSIT_MSG);
        }

        return resultMap;

    }

    /**
     * 分页查询我发布的团
     * @param example
     * @param userId
     * @return
     */
    public List<Collage> findMyPublishCollageListByUserIdAndPage(CollageExample example ,String userId){
        Criteria criteria = example.createCriteria();
        criteria.andIsEffectiveEqualTo(DBConst.TRUE);
        criteria.andUserIdEqualTo(userId);
        List<Collage> collages = this.list(example);
        return collages;
    }

    /**
     * 获取拼团高级设置详情也
     * @param collageId
     * @return
     */
    public Map<String,Object> getGJSkuDetailVoByCollageId(String collageId){
        Map<String,Object> resultMap = new HashMap<>();
        Collage collage = this.get(collageId);
        if(collage!=null){
            GJSkuDetailVo gjSkuDetailVo = new GJSkuDetailVo();
            int maxBug = collage.getMaxCount() == null?1: collage.getMaxCount();
            gjSkuDetailVo.setMaxBug(maxBug);
            int totalInventorys = collage.getTotalInventorys() ==null?0:collage.getTotalInventorys();
            gjSkuDetailVo.setTotalIntentory(totalInventorys);
            List<CollageCategory> collageCategories = this.collageCategoryService.findCollageCategoryByCollageId(collage.getId());
            List<SkuDetailVo> skuDetailVos = new ArrayList<>();
            if(!collageCategories.isEmpty()){
                for(CollageCategory collageCategory:collageCategories){
                    SkuDetailVo skuDetailVo = new SkuDetailVo();
                    skuDetailVo.setCollageCategoryId(collageCategory.getId());
                    skuDetailVo.setSkuName(collageCategory.getCategoryName());
                    List<CollageSku> collageSkus = this.collageSkuService.findCollageSkuByCategoryId(collageCategory.getId());
                    StringBuffer skuName = new StringBuffer();
                    for(CollageSku collageSku : collageSkus){
                        skuName.append(collageSku.getSkuName()).append("/");
                    }
                    skuDetailVo.setSkuValue(skuName.toString());
                    skuDetailVos.add(skuDetailVo);
                }
            }
            gjSkuDetailVo.setSkuDetailVos(skuDetailVos);
            resultMap.put(BaseCode.DATA,gjSkuDetailVo);
            resultMap.put(BaseCode.CODE,BaseCode.SUCCESS_ERROR_CODE);
            resultMap.put(BaseCode.MSG,BaseCode.SUCCESS_ERROR_MSG);
        }else{
            //提示拼团不存在
            resultMap.put(BaseCode.CODE,BaseCode.HPP_COLLAGE_NOT_EXIST_CODE);
            resultMap.put(BaseCode.MSG,BaseCode.HPP_COLLAGE_NOT_EXIST_MSG);
        }
        return resultMap;
    }

    /**
     * 获取规格匹配详情
     * @param collageId
     * @return
     */
    public Map<String,Object> getSkuPropertyDetail(String collageId){
        Map<String,Object> resultMap = new HashMap<>();
        //查看拼团是否存在
        Collage collage = this.get(collageId);
        if(collage!=null){
            //获取商品的sku
            List<CollageSku> collageSkus = this.collageSkuService.findCollageSkuByCollageId(collageId);
            if(!collageSkus.isEmpty()){
                //效验该拼团是否存在规格匹配
                List<CollageCategory> collageCategories = this.collageCategoryService.findCollageCategoryByCollageId(collageId);
                Map<String,Object> skuPropertyMap = this.collageSkuPropertyService.matchSkuProperty(collageCategories);
                if(this.collageSkuPropertyService.isExistCollageSkuPropertyByCollageId(collageId)){
                    //存在
                    //效验是否有修改 或者添加
                    List<String> skuPropertyList = new ArrayList<String> ();
                    skuPropertyList.addAll(skuPropertyMap.keySet());
                    //查看不需要的属性Property
                    List<CollageSkuProperty> skuProperties = this.collageSkuPropertyService.findCollageSkuPropertyByCollageIdAndNotExistProperties(collageId,skuPropertyList);
                    //删除不需要的属性Property
                    for(CollageSkuProperty collageSkuProperty : skuProperties)
                        this.collageSkuPropertyService.delete(collageSkuProperty);
                    //效验每一个规格property
                    for(String key:skuPropertyMap.keySet()){
                        CollageSkuProperty collageSkuProperty = this.collageSkuPropertyService.getCollageSkuPropertyByCollageIdAndProperty(collageId,key);
                        if(collageSkuProperty==null){
                            this.collageSkuPropertyService.addCollageSkuProperty(collageId,key,0, (String) skuPropertyMap.get(key));
                        }else{
                            collageSkuProperty.setPropertyName((String)skuPropertyMap.get(key));
                            this.collageSkuPropertyService.edit(collageSkuProperty);
                        }
                    }
                }else{
                    //不存在
                    //查询拼团属性类型
                    //直接匹配 并存入数据库 并返回数据
                    for(String key : skuPropertyMap.keySet()){
                        this.collageSkuPropertyService.addCollageSkuProperty(collageId,key,0, (String) skuPropertyMap.get(key));
                    }
                }
                //返回拼团属性值类型 以及库存
                List<CollageSkuProperty> collageSkuProperties = this.collageSkuPropertyService.findCollageSkuPropertyByCollageId(collageId);
                List<SkuPropertyVo> skuPropertyVos = new ArrayList<>();
                for(CollageSkuProperty collageSkuProperty : collageSkuProperties){
                    SkuPropertyVo skuPropertyVo = this.collageSkuPropertyService.collageSkuPropertyWrapToSkuPropertyVo(collageSkuProperty);
                    skuPropertyVos.add(skuPropertyVo);
                }
                resultMap.put(BaseCode.DATA,skuPropertyVos);
                resultMap.put(BaseCode.CODE,BaseCode.SUCCESS_ERROR_CODE);
                resultMap.put(BaseCode.MSG,BaseCode.SUCCESS_ERROR_MSG);
            }else{
                // 提示该拼团没有规格
                resultMap.put(BaseCode.CODE,BaseCode.HPP_COLLAGE_SKU_NOT_EXIST_CODE);
                resultMap.put(BaseCode.MSG,BaseCode.HPP_COLLAGE_SKU_NOT_EXIST_MSG);
            }
        }else{
            //提示拼团不存在
            resultMap.put(BaseCode.CODE,BaseCode.HPP_COLLAGE_NOT_EXIST_CODE);
            resultMap.put(BaseCode.MSG,BaseCode.HPP_COLLAGE_NOT_EXIST_MSG);
        }
        return resultMap;
    }

    public void saveInventorys(List<CollageSkuVo> collageSkuVos){
        this.collageSkuPropertyService.editBatchCollageSkuPropertyInventorysByCollageSkuVo(collageSkuVos);
        int totalCount = 0;
        for(CollageSkuVo collageSkuVo : collageSkuVos)
            totalCount = totalCount + collageSkuVo.getInventorys();
        String propertyId = collageSkuVos.get(0).getPropertyId();
        CollageSkuProperty collageSkuProperty = this.collageSkuPropertyService.get(propertyId);
        String collageId = collageSkuProperty.getCollageId();
        Collage collage = this.get(collageId);
        collage.setTotalInventorys(totalCount);
        this.edit(collage);
    }

    /**
     * 删除拼团的属性的Id
     * @param collageId 拼团Id
     * @param collageCategoryId 拼团属性Id
     * @return
     */
    public Map<String,Object> delCollageSkuCategory(String collageId,String collageCategoryId){
        Map<String,Object> resultMap = new HashMap<>();
        Collage collage = this.get(collageId);
        if(collage!=null){
            CollageCategory category = this.collageCategoryService.get(collageCategoryId);
            if(category!=null){
                if(collage.getId().equals(category.getCollageId())){
                    //删除属性类型
                    this.collageCategoryService.delete(category);
                    //删除属性下的所有属性值
                    List<CollageSku> collageSkus = this.collageSkuService.findCollageSkuByCategoryId(category.getId());
                    for(CollageSku collageSku : collageSkus)
                        this.collageSkuService.delete(collageSku);
                    resultMap.put(BaseCode.CODE,BaseCode.SUCCESS_ERROR_CODE);
                    resultMap.put(BaseCode.MSG,BaseCode.SUCCESS_ERROR_MSG);
                }else{
                    //提示拼团Id不一致 无权操作
                    resultMap.put(BaseCode.CODE,BaseCode.HPP_COLLAGE_ID_NOT_MATCH_CODE);
                    resultMap.put(BaseCode.MSG,BaseCode.HPP_COLLAGE_ID_NOT_MATCH_MSG);
                }
            }else{
                //提示拼团类型不存在
                resultMap.put(BaseCode.CODE,BaseCode.HPP_COLLAGE_CATEGORY_NOT_EXIST_CODE);
                resultMap.put(BaseCode.MSG,BaseCode.HPP_COLLAGE_CATEGORY_NOT_EXIST_MSG);
            }
        }else{
            //提示拼团不存在
            resultMap.put(BaseCode.CODE,BaseCode.HPP_COLLAGE_NOT_EXIST_CODE);
            resultMap.put(BaseCode.MSG,BaseCode.HPP_COLLAGE_NOT_EXIST_MSG);
        }
        return resultMap;
    }

    /**
     * 查看参见拼团的团员
     * @param collagId
     * @return
     */
    public List<CollageUserVo> findCollageUserByCollageId(String collagId){
        List<Order> orders =  this.orderService.findJoinCollageOrderByCollageId(collagId);
        List<CollageUserVo> collageUserVos = new ArrayList<>();
        for(Order order : orders){
            CollageUserVo collageUserVo = new CollageUserVo();
            HppUser user = this.hppUserService.get(order.getBuyUserId());
            if(user!=null){
                collageUserVo.setHeadImage(user.getHeadImg());
                collageUserVo.setName(user.getNickName());
                String timeContent = this.getJoinTimeContent(order.getCreateTime());
                collageUserVo.setTimeContent(timeContent);
                collageUserVos.add(collageUserVo);
            }else
                continue;
        }
        return collageUserVos;
    }

    /**
     * 获取参团时间描叙 几年前 几月前 几天前 几小时前 几分钟前
     * @param joinDate
     * @return
     */
    public String  getJoinTimeContent(Date joinDate){
        StringBuffer content = new StringBuffer();
        Date nowDate = new Date();
        int differYear = DateHelper.getDifferYear(joinDate,nowDate);
        if(differYear>0)
           return  content.append(differYear).append("年前").toString();
        int differMonth = DateHelper.getDifferMonth(joinDate,nowDate);
        if(differMonth>0)
            return content.append(differMonth).append("月前").toString();
        long differDay = DateHelper.getDifferDay(nowDate,joinDate);
        if(differDay>0)
            return content.append(differDay).append("天前").toString();
        long differHour = DateHelper.getDifferHour(nowDate,joinDate);
        if(differHour>0)
            return content.append(differHour).append("小时前").toString();
        long differMinute = DateHelper.getDifferMinute(nowDate,joinDate);
        if(differMinute>0)
            return content.append(differHour).append("分钟前").toString();
        return content.toString();
    }
    public Map<String,Object> shareImage(String collageId,String url){
        Map<String,Object> resultMap = new HashMap<>();
        Collage collage = this.get(collageId);
        if(collage!=null){
            StringBuffer urlsb = new StringBuffer("https://www.uhuijia.com.cn/image-server/uploadImage/oss/hpp/share");
            StringBuffer param = new StringBuffer();
            param.append("?");
            param.append("url=").append(url).append("&");
            param.append("title=").append(collage.getTitle()).append("&");
            param.append("originalPrice=").append(collage.getOriginalPrice()).append("&");
            HppUser user = this.hppUserService.get(collage.getUserId());
            param.append("nickName=").append(user.getNickName()).append("&");
            List<CollageImageVideo> imageVideos = this.collageImageVideoService.findCollageImageVideoByCollageIdAndType(collageId,ImageVideoType.Image);
            if(!imageVideos.isEmpty())
                param.append("mainImageUrl=").append(imageVideos.get(0).getUrl()).append("&");
            List<CollageCondition> collageConditions = this.collageConditionService.findCollageConditionByCollageId(collageId);
            if(!collageConditions.isEmpty())
                param.append("collagePrice=").append(collageConditions.get(0).getCollagePrice());
            String result = HttpRequestUtils.sendPost(urlsb.toString(), param.toString());
            JSONObject fromObject = JSONObject.fromObject(result);
            String resultRemote = fromObject.getString("errorCode");
            if( "10000".equals(resultRemote)){
                resultMap.put(BaseCode.DATA, fromObject.getString("data"));
            }
            resultMap.put(BaseCode.CODE,BaseCode.SUCCESS_ERROR_CODE);
            resultMap.put(BaseCode.MSG,BaseCode.SUCCESS_ERROR_MSG);
        }else{
            //提示拼团不存在
            resultMap.put(BaseCode.CODE,BaseCode.HPP_COLLAGE_NOT_EXIST_CODE);
            resultMap.put(BaseCode.MSG,BaseCode.HPP_COLLAGE_NOT_EXIST_MSG);
        }
        return resultMap;
    }

    /**
     * 查询直接到账的拼团 以及 发布结束时间 超过多少天的
     * @param day
     * @return
     */
    public List<Collage> findCollageEndAndOutOfDaysAndDirect(int day){
        Date date = new Date();
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DATE, -day);
        Date afterDate = calendar.getTime();
        String afterDateStr = DateHelper.formatDate(afterDate,"yyyy-MM-dd");
        Map<String,Object> params = new HashMap<>();
        params.put("outDate",afterDateStr);
        List<Collage> collages = this.collageDao.findCollageEndAndOutOfDaysAndDirect(params);
        return collages;
    }

    /**
     * 直接到账打款给团长 (定时器调用)
     * @param day
     */
    public  void  directPayToCollageHead(int day){
        //查询直接到账的拼团 以及 发布结束时间 超过多少天的 并且成团
        List<Collage> collages = this.findCollageEndAndOutOfDaysAndDirect(day);
        for(Collage collage : collages){
            //效验拼团是否成团
            CollageSuccess collageSuccess = this.isSuccessCollage(collage);
            if(CollageSuccess.Success.getState().equals(collageSuccess.getState())){
                //查询拼团下已完成的订单
                List<Order> orders = this.orderService.findJoinCollageOrderByCollageId(collage.getId());
                for(Order order : orders){
                    //效验每个订单是否已经打款给团长
                    if(TradeCollageType.No.getType().equals(order.getIsTradeCollage())){
                        //打款给团长
                        this.hppUserService.operateUserMoney(order.getSellerUserId(),order.getActualPay(),OperateType.add,FlowType.InCome,FlowMethod.OrderTrade,order.getOrderNo(),FlowSource.Order,order.getBuyUserId());
                    }
                }
            }
        }


    }

}